package com.gio.tools.common.utils;

import javax.sql.DataSource;
import java.sql.*;

/**
 * hive工具类
 *
 * @author tm
 * @version 2020/12/15 17:24
 */
public class HiveUtils {

    private Connection connection;
    private Statement statement;
    private ResultSet resultSet;

    public HiveUtils(DataSource druidDataSource) throws SQLException {
        connection = druidDataSource.getConnection();
        statement = connection.createStatement();
    }

    public void destruction() throws SQLException {
        if (resultSet != null) {
            resultSet.close();
        }
        if (statement != null) {
            statement.close();
        }
        if (connection != null) {
            connection.close();
        }
    }

    /**
     * 运行SQL
     *
     * @param sql
     * @return
     */
    public ResultSet runSql(String sql) throws SQLException {
        resultSet = statement.executeQuery(sql);
        return resultSet;
    }

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.github.housepower.jdbc.ClickHouseDriver");
        Connection connection = DriverManager.getConnection("jdbc:clickhouse://129.211.46.206:8123/gio");

        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT * from gio.crmOrder limit 10");
        System.out.println(resultSet);
    }

}
